package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.entity.Category;
import com.example.mapper.CategoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    public List<Category> selectAll() {
        return categoryMapper.selectAll(null);
    }


    public PageInfo<Category> selectPage(Integer pageNum, Integer pageSize, String name) {
        // 开启分页查询
        PageHelper.startPage(pageNum,pageSize);
        System.out.println("name======>"+name);
        List<Category> list = categoryMapper.selectAll(name);
        return PageInfo.of(list);
    }
    public void add(Category category){
        categoryMapper.insert(category);
    }

    public void update(Category category) {
//        if(categoryMapper.selectByCategoryname(category.getCategoryname())!=0){
//            throw new CustomerException("账号重复");
//        }
        categoryMapper.updateById(category);
    }

    public void deleteById(Integer id) {
        categoryMapper.deleteById(id);
    }
    public Category selectById(Integer id) {
        return categoryMapper.selectById(id);
    }

//    public void deleteBatch(List<Category> list) {
//        for (Category category : list) {
//            this.deleteById(category.getId());
//        }
//    }

}